
$('.extract-ks').click(function(){
	var extractid = $(this).parents('tr').find('.extractid').html().trim();
	$(this).parents('tr').find('.cardnumberinput').trigger('select');
	document.execCommand('copy');
	toastr.info('银行卡号已复制到粘贴板');
	action('KS',extractid,'',$(this));
});

$('.confirmbh').click(function(){
	var extractid = $('input[name="extractid"]').val();
	var explaim = $('textarea[name="explaim"]').val();
	if(!explaim){
		toastr.warning('说明不能为空！');
		return false;
	}
	action('BH',extractid,explaim);
});
$('#exampleModal').on('show.bs.modal', function (event) {
  var button = $(event.relatedTarget) // Button that triggered the modal
  var recipient = button.data('whatever') // Extract info from data-* attributes
  // If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
  // Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
  var modal = $(this)
  // modal.find('.modal-title').text('New message to ' + recipient)
  modal.find('.modal-body input[name="extractid"]').val(recipient);
})
var yclclick = function(){
	var extractid = $(this).parents('tr').find('.extractid').html().trim();
	action('YCL',extractid,'',$(this));
}
$('.extract-ycl').click(yclclick);
function action(ac,extractid,desc,this_) {
	if(!desc){
		var desc = false;
	}
	$.ajaxSetup({
	    headers: {
	        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
	    }
	});
	$.post('/coupon/extract/action',{'action':ac,'extractid':extractid,'extract_desc':desc},function(response){
		if(response.success){
			var pareneme = $(this_).parents('tr');
			switch(ac){
				case 'KS':
				    pareneme.find('.extract-ks').unbind('click');
					pareneme.find('.extract-ks').attr('class','extract-ycl').html('已处理');
					pareneme.find('.extract-ycl').click(yclclick);
				    break;
				case 'BH':
					$('#exampleModal').modal('hide');
					$('input[name="extractid"]').val('');
					$('textarea[name="explaim"]').val('');
					$('.bhextr'+extractid).html('正在修改');
				    break;
				case 'YCL':
					pareneme.find('.bankcz').html('处理完成');
				    break;
			}
			toastr.success(response.message);
		}else{
			toastr.error(response.message);
		}
	});
}
